import logging, yagmail, HTMLTestRunner, HTMLTestRunner_cn, HTMLTestRunner_PY3, XTestRunner, BeautifulReport, time


class Tools():
    filepath = time.strftime('%Y-%M-%d %H-%m-%s')
    # 设置日志：
    def set_logging(self):
        log = logging.basicConfig(filename=Tools.filepath+'.log', filemode='a+', level=logging.DEBUG,
                                  format='%(levelname)s -> %(asctime)s -> %(message)s -> %(filename)s -> %(lineno)d 行')
        return log

    # 生成测试报告
    def Report1(self):
        report1 = HTMLTestRunner.HTMLTestRunner(open(Tools.filepath+'.html', 'wb'), title='维度科技接口自动化测试报告', description='维度科技测试报告请注意查收！')
        return report1

    def Report2(self):
        report2 = HTMLTestRunner_cn.HTMLTestRunner(open(Tools.filepath+'.html', 'wb'), title='维度科技接口自动化测试报告', description='维度科技测试报告请注意查收')
        return report2

    def Report3(self):
        report3 = HTMLTestRunner_PY3.HTMLTestRunner(open(Tools.filepath+'.html', 'wb'), title='维度科技接口自动化测试报告', description='维度科技测试报告请注意查收')
        return report3

    def Report4(self):
        report4 = XTestRunner.HTMLTestRunner(open(Tools.filepath+'.html', 'wb'), title='维度科技接口自动化测试报告', description='维度科技测试报告请注意查收', rerun=1, language='zh-CN')
        return report4

    def Report5(self, suite):
        report5 =BeautifulReport.BeautifulReport(suites=suite)
        # log_path = '.'
        # 和report_dir = '.'
        # 表示将生成的日志文件和测试报告保存到当前工作目录中
        report5.report(filename=Tools.filepath+'.html', description='维度科技测试报告请注意查收', log_path='.', report_dir='.')

    # 发送邮箱
    def send_mail(self):
        mail = yagmail.SMTP(user='2318636512@qq.com', password='', host='smtp.qq.com')
        mail.send(to='2318636512@qq.com', subject='关于维度科技的接口自动化测试日志和报告！', contents=['日志和报告已发送，请注意查收', Tools.filepath+'.log', Tools.filepath+'.html'])
        mail.close()















